package com.wudi;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File;

public class UtilsXML {
    public static String ReadNameFromXML() {
        String className = "";
        try {
            //读取XML文件
            DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = dFactory.newDocumentBuilder();
            Document doc;
            doc = builder.parse(new File("src//config.xml"));

            //获取包含类名的文本结点
            NodeList nl = doc.getElementsByTagName("className");
            Node classNode = nl.item(0).getFirstChild(); //修改节点编号,没输入默认是第一个节点
            className = classNode.getNodeValue();


        } catch (Exception ex) {
            ex.printStackTrace();

        } finally {
        }
        return className;
    }
    public static String ReadNameFromXML(Integer no) {
        String className = "";
        try {
            //读取XML文件
            DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = dFactory.newDocumentBuilder();
            Document doc;
            doc = builder.parse(new File("src//config.xml"));

            //获取包含类名的文本结点
            NodeList nl = doc.getElementsByTagName("className");
            Node classNode = nl.item(no).getFirstChild(); //修改节点编号
            className = classNode.getNodeValue();


        } catch (Exception ex) {
            ex.printStackTrace();

        } finally {
        }
        return className;
    }
}
